<?php 
/**
 * message底层操作
 DROP TABLE IF EXISTS `dict_message`;
CREATE TABLE `dict_message` (
  `m_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type` int(10) unsigned NOT NULL COMMENT '消息类型，与dict_message_type形成外键关联',
  `content` varchar(255) DEFAULT '这是一个空消息',
  `status` tinyint(2) NOT NULL,
  `url` varchar(50) DEFAULT '#',
  `u_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`m_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 */
Class MessageModel extends Model{
  private $unread = 0;
  private $read = 1;

  /**
   * 获取某用户的所有未读消息
   * @param  int    $u_id [description]
   * @return [type]       [description]
   */
  public function getAllUnreadMessageByUid(int $u_id)
  {
    return $this->where('u_id=' . $u_id . " and status=" . $this->unread)
                ->order('createtime desc')
                ->limit(0, 20)
                ->select();
  }

  /**
   * 获得某用户的所有已读消息
   * @param  int    $u_id [description]
   * @return [type]       [description]
   */
  public function getAllReadMessageByUid(int $u_id)
  {
    return $this->where('u_id=' . $u_id . " and status=" . $this->read)->order('createtime desc')->select();
  }

  /**
   * 获得某一用户的某一类型的消息
   * @param  int    $type [description]
   * @param  int    $u_id [description]
   * @return [type]       [description]
   */
  public function getAllMessageByType(int $type, int $u_id)
  {
    return $this->where('type=' . $type . " and u_id=" . $u_id)->select();
  }


}
 ?>